<div class="crayons-card crayons-card--content-rows" id="comment-templates">
  <header>
    <h2 class="crayons-subtitle-1">
      <%= t("views.settings.extensions.comment.heading") %>
    </h2>
    <p class="color-base-70"><%= t("views.settings.extensions.comment.desc_html") %></p>
    </p>
  </header>

  <% if @personal_response_templates.present? %>
    <section>
      <h3 class="crayons-subtitle-3">
        <%= t("views.settings.extensions.comment.saved") %>
      </h3>
      <%= render partial: "response_template", collection: @personal_response_templates %>
    </section>
  <% end %>

  <% if @trusted_response_templates.present? %>
    <section>
      <h3 class="crayons-subtitle-3">
        <%= t("views.settings.extensions.comment.trusted") %>
      </h3>
      <%= render partial: "response_template", collection: @trusted_response_templates %>
    </section>
  <% end %>

  <%= form_with model: @response_template do |f| %>
    <section class="grid gap-3">
      <% if @response_template&.persisted? %>
        <% title = params[:previous_title] || @response_template.title %>
        <% content = params[:previous_content] || @response_template.content %>
        <h3 class="crayons-subtitle-3">
          <%= t("views.settings.extensions.comment.edit_template") %>
        </h3>
        <a href="/settings/response-templates"><%= t("views.settings.extensions.comment.create") %></a>

      <% else %>
        <% title = params[:previous_title] %>
        <% content = params[:previous_content] %>
        <h3 class="crayons-subtitle-3">
          <%= t("views.settings.extensions.comment.add") %>
        </h3>
      <% end %>

      <div class="crayons-field">
        <%= f.label :title, class: "crayons-field__label" %>
        <p class="crayons-field__description">
          <%= t("views.settings.extensions.comment.cue") %>
        </p>
        <%= f.text_field :title, placeholder: "...", value: title, class: "crayons-textfield" %>
      </div>
      <div class="crayons-field">
        <%= f.label :content, "Comment body (Markdown)", class: "crayons-field__label" %>
        <%= f.text_area :content, value: content, class: "crayons-textfield" %>
      </div>

      <% if policy(ResponseTemplate).admin_create? && @response_template.new_record? %>
        <div class="crayons-field">
          <fieldset>
            <legend class="screen-reader-only">Template type</legend>
            <%= f.radio_button :type_of, "personal_comment",
                               checked: @response_template.type_of != "mod_comment",
                               class: "crayons-radio", role: "radio" %>
            <%= label_tag "response_template_type_of_personal_comment", "Personal" %>

            <%= f.radio_button :type_of, "mod_comment",
                               class: "crayons-radio", role: "radio" %>
            <%= label_tag "response_template_type_of_mod_comment", "Trusted User" %>
          </fieldset>
        </div>
      <% end %>

      <div>
        <button type="submit" class="crayons-btn"><%= t("views.settings.extensions.comment.save") %></button>
      </div>
    </section>
  <% end %>
  </div>
